package com.ruoyi.system.service.impl;

import java.text.NumberFormat;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.WorkLogMapper;
import com.ruoyi.system.domain.WorkLog;
import com.ruoyi.system.service.IWorkLogService;

/**
 * 跟踪日志Service业务层处理
 * 
 * @author ZYT
 * @date 2020-08-31
 */
@Service
public class WorkLogServiceImpl implements IWorkLogService 
{
    @Autowired
    private WorkLogMapper workLogMapper;

    /**
     * 查询跟踪日志
     * 
     * @param workId 跟踪日志ID
     * @return 跟踪日志
     */
    @Override
    public WorkLog selectWorkLogById(Long workId)
    {
        return workLogMapper.selectWorkLogById(workId);
    }

    /**
     * 查询跟踪日志列表
     * 
     * @param workLog 跟踪日志
     * @return 跟踪日志
     */
    @Override
    public List<WorkLog> selectWorkLogList(WorkLog workLog)
    {
        return workLogMapper.selectWorkLogList(workLog);
    }

    /**
     * 新增跟踪日志
     * 
     * @param workLog 跟踪日志
     * @return 结果
     */
    @Override
    public int insertWorkLog(WorkLog workLog)
    {
        return workLogMapper.insertWorkLog(workLog);
    }

    /**
     * 修改跟踪日志
     * 
     * @param workLog 跟踪日志
     * @return 结果
     */
    @Override
    public int updateWorkLog(WorkLog workLog)
    {
        return workLogMapper.updateWorkLog(workLog);
    }

    /**
     * 批量删除跟踪日志
     * 
     * @param workIds 需要删除的跟踪日志ID
     * @return 结果
     */
    @Override
    public int deleteWorkLogByIds(Long[] workIds)
    {
        return workLogMapper.deleteWorkLogByIds(workIds);
    }

    /**
     * 删除跟踪日志信息
     * 
     * @param workId 跟踪日志ID
     * @return 结果
     */
    @Override
    public int deleteWorkLogById(Long workId)
    {
        return workLogMapper.deleteWorkLogById(workId);
    }

    /**
     * 读码率汇总
     * @param workLog
     * @return
     */
    @Override
    public List<WorkLog> selectBcrRead(WorkLog workLog)
    {
        return workLogMapper.selectBcrRead(workLog);
    }

    /**
     * 出口分拣统计
     * @param workLog
     * @return
     */
    @Override
    public List<WorkLog> selectLevelSeorting(WorkLog workLog)
    {
        return workLogMapper.selectLevelSeorting(workLog);
    }

    /**
     * 时间段流量汇总
     * @param workLog
     * @return
     */
    @Override
    public List<WorkLog> selectTrafficquery(WorkLog workLog)
    {
        return workLogMapper.selectTrafficquery(workLog);
    }

    /**
     * 异常汇总
     * @param workLog
     * @return
     */
    @Override
    public List<WorkLog> selectUnusual(WorkLog workLog)
    {
    	List<WorkLog> unusualList = workLogMapper.selectUnusual(workLog);
    	/*
    	 * 计算读码率和分拣率
    	 */
    	for(WorkLog log : unusualList) {
    		String readPercent = "0";
    		String sortPercent = "0" ;
    		int sumNum = Integer.parseInt(log.getSumSorting());//总数
    		int readNum = sumNum - Integer.parseInt(log.getCase1());//读码成功数
    		int successSortNum = sumNum - Integer.parseInt(log.getNoreadSorting());//分拣成功
  	        NumberFormat numberFormat=NumberFormat.getPercentInstance();
  	        numberFormat.setMinimumFractionDigits(2);
  	        if(sumNum!=0) {
  	        	 readPercent = numberFormat.format(((double)readNum)/((double)sumNum));
  	  	        sortPercent = numberFormat.format(((double)successSortNum)/((double)sumNum));
  	        }
  	        log.setPercentRead(readPercent);		
    		log.setPercentSorting(sortPercent);	
    	}



        return unusualList;
    }
}
